//
//  MoreGameLayer.m
//  MyCrow
//
//  Created by guanhongjun on 12-7-5.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "MoreGameLayer.h"


@implementation MoreGameLayer
+(id) scene {
    CCScene* scene = [CCScene node];
    CCLayer* layer = [MoreGameLayer node];
    [scene addChild:layer];
    return scene;
}

-(void) goToAd:(id)sender {
    CCLOG(@"sender tag = %d, url is %@\n", [sender tag], [urlArr objectAtIndex:0]);
    
    [[UIApplication sharedApplication] openURL:
     [NSURL URLWithString:[urlArr objectAtIndex:[sender tag]]]];
}

-(id) init {
    if (self = [super init]) {
        // 各个广告对应的网址
        urlArr = [[NSArray alloc] initWithObjects:@"http://www.baidu.com", @"http://www.google.com", 
                  @"http://tieba.baidu.com/index.html", @"http://zhidao.baidu.com/",
                  @"http://image.baidu.com/", @"http://store.apple.com/cn?afid=p219%7CBDCN&cid=AOS-CN-KWB",
                  @"http://www.163.com", @"http://zhidao.baidu.com/", @"http://w35.mail.qq.com/cgi-bin/today?sid=ZRKtIxEUAKVQTV8Q2zJ1dFXi,4,cS11UWArT2m0.&first=1", nil];
        
        // 生成菜单
        CCMenu* menu = [CCMenu menuWithItems:nil];
        menu.anchorPoint = ccp(0, 0);
        menu.position = ccp(0, 0);
        [self addChild:menu];
        for (int i = 0; i < 9; i++) {
            CCSprite* sp = [CCSprite spriteWithFile:[NSString stringWithFormat:@"ad%d.png", i]];
            CCMenuItemImage* menuItem = [CCMenuItemImage itemFromNormalSprite:sp selectedSprite:nil target:self selector:@selector(goToAd:)];
            menuItem.tag = i;
            menuItem.anchorPoint = ccp(0, 0);
            menuItem.position = ccp(55+130*(i%3), 5+110*(i/3));
            [menu addChild:menuItem];
        }
    }
    return self;
}

-(void) dealloc {
    [urlArr release];
    [super dealloc];
}

@end
